/*
 * Filename:    KpiBatchDaoImpl.java
 * Copyright:   2014 中国平安保险（集团）股份有限公司 版权所有
 * Company:     平安科技养老险及健康险系统开发部
 * Create at:   2014年10月10日
 */
package com.paic.mhis.hcpms.quota.calculationreport.calculationjob.intergration.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Component;

import com.paic.mhis.hcpms.quota.calculationreport.calculationjob.dto.KpiBatchDTO;
import com.paic.mhis.hcpms.quota.calculationreport.calculationjob.dto.KpiBatchDetailDTO;
import com.paic.mhis.hcpms.quota.calculationreport.calculationjob.dto.KpiBatchJobLogDTO;
import com.paic.mhis.hcpms.quota.calculationreport.calculationjob.dto.KpiBatchParamterDTO;
import com.paic.mhis.hcpms.quota.calculationreport.calculationjob.intergration.dao.KpiBatchDao;
import com.paic.pafa.biz.dao.BaseDAO;

@Component("kpiBatchDao")
public class KpiBatchDaoImpl extends BaseDAO implements KpiBatchDao {

	/**
	 * 根据状态查询指标批次主表信息
	 */
	@Override
	public List<KpiBatchDTO> queryKpiBatchDTOByStatus(KpiBatchParamterDTO paramter) {
		return (List<KpiBatchDTO>) this._queryForList("calculationjob.queryKpiBatchDtoInfo", paramter);

	}

	/**
	 * 插入指标批次明细表记录
	 */
	public void insertKpiBatchDetailDtoInfo(KpiBatchDetailDTO bean) {

		this._insert("calculationjob.addKpiBatchDetailDtoInfo", bean);
	}

	/**
	 * 根据指标批次主表的id，更新当前记录状态
	 */
	public void updateKpiBatchDtoInfo(KpiBatchParamterDTO paramter) {
		this._update("calculationjob.updateKpiBatchDtoInfo", paramter);
	}

	/**
	 * 根据状态加载指标批次明细表记录
	 */
	@Override
	public List<KpiBatchDetailDTO> queryKpiBatchDetailDTO(KpiBatchParamterDTO paramter) {
		return (List<KpiBatchDetailDTO>) this._queryForList("calculationjob.queryKpiBatchDetailDtoInfo", paramter);
	}

	/**
	 * 根据指标批次明细表的主键更新当前记录状态
	 */
	public void updateKpiBatchDetailDTOStatus(String id, String status) {
		Map<String, Object> updateMap = new HashMap<String, Object>();
		updateMap.put("status", status);
		updateMap.put("idKpiBatchDetail", id);
		this._update("calculationjob.updateKpiBatchDetailDtoInfo", updateMap);

	}

	/**
	 * 根据状态查询智能审核执行计划表 和指标批次主表的差集
	 */
	@Override
	public void queryKpiBatchGegionCodeDTOByStatus() {
		Map<String, Object> map = new HashMap<String, Object>();
		this._insert("calculationjob.queryKpiBatchMinusInfo", map);

	}

	/**
	 * 插入指标批次主表信息
	 */
	@Override
	public void insertKpiBatchInfo(KpiBatchDTO bean) {
		this._insert("calculationjob.insertKpiBatchDtoInfo", bean);
	}

	/**
	 * 查询生成批次编号的sequence
	 */
	@Override
	public Long queryBatchNoSequence() {
		return (Long) this._queryForObject("calculationjob.queryBatchSequenece", Long.class);

	}

	/**
	 * 保存job日志记录
	 */
	@Override
	public void insertBacthJobLogDTO(KpiBatchJobLogDTO bean) {

		this._insert("calculationjob.insertKpiBatchJobLogDTO", bean);
	}

	/**
	 * 更新批次主表的临时主建
	 */
	@Override
	public void updateKpiBatchDtoInfoTempBatchId(String tempBatchId) {
		Map<String, Object> updateMap = new HashMap<String, Object>();
		updateMap.put("tempBatch", tempBatchId);
		this._update("calculationjob.updateKpiBatchDtoInfoTempBatch", updateMap);

	}

	/**
	 * 根据状态和临时主建更新批次次表的状态
	 */
	@Override
	public void updateKpiBatchDetailDTOTempBatchByStatus(String tempBatch, String status) {
		Map<String, Object> updateMap = new HashMap<String, Object>();
		updateMap.put("tempBatch", tempBatch);
		updateMap.put("status", status);
		this._update("calculationjob.updateKpiBatchDetailDtoInfoTempBatch", updateMap);

	}

	/**
	 * 根据id 将状态和tempBatch更新为空
	 */
	@Override
	public void updateBatchDetailTempBatchIsNull(String status, String id) {
		Map<String, Object> updateMap = new HashMap<String, Object>();
		updateMap.put("status", status);
		updateMap.put("idKpiBatchDetail", id);
		this._update("calculationjob.updateKpiBatchDetailDtoInfoAndTempBatch", updateMap);

	}
}
